package kliment.geom {
	import flash.geom.Point;
	
	import kliment.math.Calc;
	
	/**
	* ...
	* @author Kliment
	*/
	public class Geom {
		static public const FULL_TUTN:int = 360;
		static public const HALF_TUTN:int = 180;
		static public const NORTH:int = 0;
		static public const EAST:int = 90;
		static public const SOUTH:int = 180;
		static public const WEST:int = 270;
		static public const HALF_PI:Number = 1.5707963267948966192313216916398;
		
		static public function radToGrad(value:Number):Number {
			return value * (180 / Math.PI);
		}
		
		static public function gradToRad(value:Number):Number {
			return value * (Math.PI / 180);
		}
		
		static public function getNormalAngle(value:Number):Number {
			while (value > Geom.FULL_TUTN)
				value -= Geom.FULL_TUTN;
			
			while (value < -Geom.FULL_TUTN)
				value += Geom.FULL_TUTN;
			
			return value;
		}
		
		static public function maxPoint(point1:Point, point2:Point, ...rest):Point {
			var forReturn:Point = _maxPoint(point1, point2);
			rest.push(forReturn);
			for (var i:int = 0; i<rest.length-1; i++){
				forReturn = _maxPoint(rest[i], rest[i+1]);
			}
			return forReturn;
		}
		
		static private function _maxPoint(point1:Point, point2:Point):Point{
			if (point1.length > point2.length)
				return point1;
			return point2;
		}
		
		static public function minPoint(point1:Point, point2:Point, ...rest):Point {
			var forReturn:Point = _minPoint(point1, point2)
			rest.push(forReturn);
			for (var i:int = 0; i<rest.length-1; i++){
				forReturn = _minPoint(rest[i], rest[i+1]);
			}
			return forReturn;
		}
		
		static private function _minPoint(point1:Point, point2:Point):Point{
			if (point2.length < point1.length)
				return point2;
			return point1;
		}
		
		static public function topPoint(point1:Point, point2:Point, ...rest):Point {
			var forReturn:Point = _topPoint(point1, point2)
			rest.push(forReturn);
			for (var i:int = 0; i<rest.length-1; i++){
				forReturn = _topPoint(rest[i], rest[i+1]);
			}
			return forReturn;
		}
		
		static private function _topPoint(point1:Point, point2:Point):Point{
			if (point2.y < point1.y)
				return point2;
			return point1;
		}
		
		static public function bottomPoint(point1:Point, point2:Point, ...rest):Point {
			var forReturn:Point = _bottomPoint(point1, point2)
			rest.push(forReturn);
			for (var i:int = 0; i<rest.length-1; i++){
				forReturn = _bottomPoint(rest[i], rest[i+1]);
			}
			return forReturn;
		}
		
		static private function _bottomPoint(point1:Point, point2:Point):Point{
			if (point2.y > point1.y)
				return point2;
			return point1;
		}
		
		static public function leftPoint(point1:Point, point2:Point, ...rest):Point {
			var forReturn:Point = _leftPoint(point1, point2)
			rest.push(forReturn);
			for (var i:int = 0; i<rest.length-1; i++){
				forReturn = _leftPoint(rest[i], rest[i+1]);
			}
			return forReturn;
		}
		
		static private function _leftPoint(point1:Point, point2:Point):Point{
			if (point2.x < point1.x)
				return point2;
			return point1;
		}
		
		static public function rightPoint(point1:Point, point2:Point, ...rest):Point {
			var forReturn:Point = _rightPoint(point1, point2)
			rest.push(forReturn);
			for (var i:int = 0; i<rest.length-1; i++){
				forReturn = _rightPoint(rest[i], rest[i+1]);
			}
			return forReturn;
		}
		
		static private function _rightPoint(point1:Point, point2:Point):Point{
			if (point2.x > point1.x)
				return point2;
			return point1;
		}
		
		static public function rotatePoint(point:Point, center:Point, angle:Number):Point {
			angle = gradToRad(angle);
			var sin:Number = Math.sin(angle);
			var cos:Number  = Math.cos(angle);
			var tempPoint:Point = new Point(point.x - center.x, point.y - center.y);
			var x:Number  = center.x + (tempPoint.x * cos - tempPoint.y * sin);
			var y:Number  = center.y + (tempPoint.x * sin + tempPoint.y * cos);
			tempPoint.x = x;
			tempPoint.y = y;
			return tempPoint;
		}
		
		static public function rotatePoints(points:Array, center:Point, angle:Number):Array {
			for (var i:* in points)
				points[i] = Geom.rotatePoint(points[i], center, angle);
			return points;
		}
		
		static public function conerBbyAC(a:Number, c:Number):Number{ 
			return Math.asin(a/c); 
		}
		
		
		static public function conerBbyac(a:Number, c:Number):Number{ 
			return Math.asin(a/c); 
		}
		
		static public function conerAbybc(b:Number, c:Number):Number{ 
			return Math.acos(b/c); 
		}
	}
}